﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;

namespace XbdSoft.WPFVersion.ViewModel
{
    public class SizeConverter:IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            try
            {
                var actualSize = (long)value;
                var size = actualSize / 1024F;
                var suffix = "KB";
                if (size > 1024) {
                    size = size / 1024;
                    suffix = "MB";
                }
                if (size > 1024)
                {
                    size = size / 1024;
                    suffix = "GB";
                }
                return string.Format("{0:f2}{1}", size, suffix);

            }
            catch { 
            }
            return "0.0KB";
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
